﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Weibo.Entity;
using Weibo.Data;
using Weibo.Config;
using Weibo.Common;

namespace Weibo.Business
{
    public class Schools
    {
        public static long CreateSchool(School school)
        {
            try
            {
                if (school == null)
                    return -1;
                return Data.Schools.CreateSchool(school);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return -1;
            }
        }

        public static IList<School> GetShoolsByLetLocType(int Location, string letter, int type)
        {
            try
            {
                return Data.Schools.GetShoolsByLetLocType(Location, letter, type);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static IList<SchoolCollege> GetShoolsCollegeByLetLocType(int uid)
        {
            try
            {
                return Data.Schools.GetShoolsCollegeByLetLocType(uid);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static IList<SchoolClass> GetShoolsClassByLetLocType(int schoolID, int collegeID)
        {
            try
            {
                return Data.Schools.GetShoolsClassByLetLocType(schoolID, collegeID);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static School GetSchoolByID(int id)
        {
            try
            {
                if (id <= 0)
                    return null;
                return Data.Schools.GetSchoolByID(id);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }

        public static IList<School> GetSchoolsByLikeName(string name)
        {
            try
            {
                if (string.IsNullOrEmpty(name)) return null;
                return Data.Schools.GetSchoolsByLikeName(name);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }

        public static IList<MiniBlog> GetTop500SchoolMiniBlogsByQuery(string where, string sortField, string sortType)
        {
            try
            {
                string query = "1=1";
                if (!string.IsNullOrEmpty(where))
                {
                    query = where;
                }
                string field = "CreateTime";
                if (!string.IsNullOrEmpty(sortField))
                {
                    field = sortField;
                }
                string type = "desc";
                if (!string.IsNullOrEmpty(sortType))
                {
                    type = sortType;
                }
                return Data.Schools.GetTopSchool500MiniBlogsByQuery(query, field, type);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static IList<MiniBlog> SearchSchoolMiniBlogForMbIndexAdvanced(int pageIndex, int pageSize, ref int rowCount, string key, int isOri, int isRet, DateTime? startTime, DateTime? endTime, int isMyself, int isMyFollow,
    long curUid, int isHavePic, int isHaveLink, int isHaveVideo, int isHaveMusic, int isHaveVote, string sort, long GroupID, int IsFriendShip)
        {
            try
            {

                return Data.Schools.SearchSchoolMiniBlogForMbIndexAdvanced(pageIndex, pageSize, ref rowCount, key, isOri, isRet, startTime, endTime, isMyself, isMyFollow, curUid, isHavePic, isHaveLink, isHaveVideo, isHaveMusic, isHaveVote, sort, GroupID, IsFriendShip);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static IList<MiniBlog> SearchSchoolMiniBlog(int pageIndex, int pageSize, ref int rowCount, string key, int isOri, int location, DateTime? startTime, DateTime? endTime, int isMyself, int isMyFollow,
                    long curUid, string someone, int isHavePic, int isHaveLink, int isHaveVideo, int isHaveMusic, int isHaveVote, string sort, long GroupID, int IsFriendShip)
        {
            try
            {

                return Data.Schools.SearchSchoolMiniBlog(pageIndex, pageSize, ref rowCount, key, isOri, location, startTime, endTime, isMyself, isMyFollow, curUid, someone, isHavePic, isHaveLink, isHaveVideo, isHaveMusic, isHaveVote, sort, GroupID, IsFriendShip);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static string SaveClassPicPath(ClassSavePicPath model)
        {
            try
            {
                if (model == null)
                    return "";
                string result = Data.Schools.SaveClassPicPath(model);
               
                        
                return result;
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return "";
            }
        }
        /// <summary>
        /// 获取班级相册里的具体内容带分页
        /// </summary>
        /// <param name="classPhotoID">classPhotoID这个是班级ID 不是相册ID</param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static IList<SchoolClassPhotoDetails> GetClassPhotoDetailList(long classPhotoID, int page, int pageSize, ref int pageCount)
        {
            try
            {
                return Data.Schools.GetClassPhotoDetailList(classPhotoID, page, pageSize, ref pageCount);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        /// <summary>
        /// 获取班级相册里的具体内容不带分页
        /// </summary>
        /// <param name="classPhotoID">classPhotoID</param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static IList<SchoolClassPhotoDetails> GetClassPhotoDetailListNoPage(long classPhotoID)
        {
            try
            {
                return Data.Schools.GetClassPhotoDetailListNoPage(classPhotoID);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static IList<TClassPhoto> GetClassPhotoList(long uid, long gid)
        {
            try
            {
                return Data.Schools.GetClassPhotoList(uid, gid);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static string DelPhoto(long photoID)
        {
            try
            {
                return Data.Schools.DelPhoto(photoID);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static string DelPhotoFolder(long classPhotoID)
        {
            try
            {
                return Data.Schools.DelPhotoFolder(classPhotoID);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
        public static SchoolClassPhotoDetails GetSinglePhotoDetail(long photoID)
        {
            try
            {
                return Data.Schools.GetSinglePhotoDetail(photoID);
            }
            catch (Exception ex)
            {
                Logs.WriteErrorLog(ex);
                return null;
            }
        }
    }
}
